package com.yer.note.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.yer.note.R;
import com.yer.note.entity.Diary;
import com.yer.note.entity.User;
import com.yer.note.utils.BaseUtils;

public class RegisterActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Button button = findViewById(R.id.register_submit);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText account = findViewById(R.id.register_account);
                EditText pwd = findViewById(R.id.register_newPwd);
                EditText pwdAgain = findViewById(R.id.register_newPwdagain);
                String Username = account.getText().toString();
                String password = pwd.getText().toString();
                String passwordAgain = pwdAgain.getText().toString();
                if(!Username.isEmpty() && !password.isEmpty() && !passwordAgain.isEmpty()){
                    if(password.equals(passwordAgain)){
                        User RegisterUser = new User(Username,password, BaseUtils.randomUUID());
                        RegisterUser.save();
                        Diary diary = new Diary("来自制作者的提示：好好探索吧","晴","#第一个日记#","guet",
                                BaseUtils.getCurrentTime(),BaseUtils.randomUUID(),RegisterUser.getMyuuid());
                        diary.save();
                        finish();
                    }else {
                        String news = "两次密码输入不一致，请检查输入";
                        BaseUtils.shortTipInCoast(RegisterActivity.this, news);
                    }
                }else{
                    String news = "请确认信息已经输入完毕!";
                    BaseUtils.shortTipInCoast(RegisterActivity.this,news);
                }
            }
        });
    }
}